<template>
  <div>
  <div id="top">
    <div id="topBar">
      <router-link :to="{name:'principle'}"><van-icon name="arrow-left" style="float: left;margin-top: 0.5rem;margin-left: 0.5rem"/>
        <p style="float: left">兑积分</p></router-link>
      <router-link :to="{path:'/exchangePoints/excPointsRec'}"><p style="float: right;color: #39a9ed;margin-right: 0.5rem" >兑换记录</p></router-link>
    </div>
    <div id="scrollPic">
      <van-swipe class="my-swipe" :autoplay="3000">
       <van-swipe-item v-for="(image, index) in images" :key="index" >
          <img v-lazy="image"/>
        </van-swipe-item>
      </van-swipe>
    </div>

  </div>
    <div class="middle">
      <van-search
        v-model="search"
        show-action
        placeholder="请输入搜索关键词"
        @search="onSearch"
      >
        <div slot="action" @click="onSearch">搜索</div>
      </van-search>
      <ul id="chooseBar">
        <li :class="{'active':out}" @click="change(1)">出行券</li>
        <li :class="{'active':discount}" @click="change(2)">优惠券</li>
        <li :class="{'active':flow}" @click="change(3)">流量包</li>
      </ul>
    </div>
    <div class="foot">
      <ul id="goodsPic">
        <li  v-for="item in goodsList" @click="detail">
          <div class="goodsPic" :style="{backgroundImage: 'url(' + item.img + ')', backgroundRepeat:'no-repeat', backgroundSize: 'cover',backgroundPosition:'center center'}"></div>
          <p class="title">{{item.title}}</p>
          <p class="price">{{item.price}}</p>
        </li>

      </ul>
    </div>
  </div>
</template>

<script>
    export default {
        name: "exchangePoints",
      data(){
          return{
            search:'',
            out:true,
            discount:false,
            flow:false,
            images: [
              'https://img.yzcdn.cn/vant/apple-1.jpg',
              'https://img.yzcdn.cn/vant/apple-2.jpg',
              'https://img.yzcdn.cn/vant/apple-1.jpg'
            ],
            goodsList:[
              {img:"https://img.yzcdn.cn/vant/apple-1.jpg",
                title:"地铁出行券",
                price:"300积分"},
              {img:"https://img.yzcdn.cn/vant/apple-1.jpg",
                title:"地铁出行券",
                price:"300积分"},
              {img:"https://img.yzcdn.cn/vant/apple-1.jpg",
                title:"地铁出行券",
                price:"300积分"},
              {img:"https://img.yzcdn.cn/vant/apple-1.jpg",
                title:"地铁出行券",
                price:"300积分"},
              {img:"https://img.yzcdn.cn/vant/apple-1.jpg",
                title:"地铁出行券",
                price:"40积分"},
            ],
          }
      },
      methods:{
          onSearch(){
            this.out=false,
              this.discount=false,
              this.flow=false
          },
        change(num){
            if (num==1){
              this.out=true,
                this.discount=false,
                this.flow=false
            }else if(num==2){
              this.out=false,
                this.discount=true,
                this.flow=false
            }else if(num==3){
              this.out=false,
                this.discount=false,
                this.flow=true
            }
        },
        detail(){
            console.log(1)
            this.$router.push('/exchangePoints/detail')
        }
      }
    }
</script>

<style scoped>
  #top{
    width: 100%;
    height:14rem;
    background: red;
    overflow: hidden;
    position: relative;
  }
  #topBar{
    height: 2rem;
    width: 100%;
    line-height: 2rem;
    background: papayawhip;
    color:black;
    font-size: 1rem;
    margin-top: 1rem;
  }
  #topBar p{
    display: inline-block;
  }
  #scrollPic{
    margin-top:1rem;
  }
  .my-swipe{
    height: 10rem;
    background-color: #39a9ed;
  }
  .my-swipe .van-swipe-item>img{
    display: inline-block;
    width: 95%;
  }
  #chooseBar{
    height: 2rem;
    background: bisque;
    border-bottom: #999999 solid 0.15rem;
    margin-top: -0.5rem;
    margin-bottom: 1rem;
  }
  #chooseBar>li{
    width: 33.3%;
    height: 2rem;
    float: left;
    font-size: 1rem;
    line-height: 2rem;
  }
  .active{
    border-bottom :#39a9ed solid 0.15rem;
    color:#39a9ed;
  }
  #goodsPic{
    width: 100%;
    height: 13rem;
    padding-left: 2.8%;
  }
  #goodsPic>li{
    background: papayawhip;
    height: 7.6rem;
    width: 44%;
    border: #39a9ed solid 0.1rem;
    float: left;
    margin-bottom: 2rem;
    margin-right: 1rem;
    position: relative;
    padding-top: 0.3rem;
  }
  .goodsPic{
    position: absolute;
    height: 5.2rem;
    width: 90%;
    left: 5%;
  }
  .title{
    font-size: 0.9rem;
    position: absolute;
    left: 0;
    bottom: 0;
    left: 0.5rem;
    bottom: 1rem;
    letter-spacing:0.1rem;
    font-weight: bold;
  }
  .price{
    font-size: 0.8rem;
    position: absolute;
    right: 0.5rem;
    bottom: 0.2rem;
    color: #39a9ed;
  }
</style>
